package com.wzgl.core.baseModel;

import com.jfinal.plugin.activerecord.IBean;
import com.jfinal.plugin.ehcache.CacheKit;
import com.jfinal.plugin.ehcache.IDataLoader;
import com.wzgl.core.base.JModel;
import com.wzgl.message.MessageKit;

@SuppressWarnings("serial")
public class BaseWebSite <M extends BaseWebSite<M>> extends JModel<M> implements IBean{
	public static final String CACHE_NAME = "website";
	public static final String METADATA_TYPE = "website";

	public static final String ACTION_ADD = "website:add";
	public static final String ACTION_DELETE = "website:delete";
	public static final String ACTION_UPDATE = "website:update";
	
	public void removeCache(Object key){
		if(key == null) return;
		CacheKit.remove(CACHE_NAME, key);
	}

	public void putCache(Object key,Object value){
		CacheKit.put(CACHE_NAME, key, value);
	}

	public M getCache(Object key){
		return CacheKit.get(CACHE_NAME, key);
	}

	public M getCache(Object key,IDataLoader dataloader){
		return CacheKit.get(CACHE_NAME, key, dataloader);
	}

	@Override
	public boolean equals(Object o) {
		if(o == null){ return false; }
		if(!(o instanceof BaseGird<?>)){return false;}

		BaseGird<?> m = (BaseGird<?>) o;
		if(m.getFid() == null){return false;}

		return m.getFid().compareTo(this.getFid()) == 0;
	}

	@Override
	public boolean save() {
		boolean saved = super.save();
		if (saved) { MessageKit.sendMessage(ACTION_ADD, this); }
		return saved;
	}

	@Override
	public boolean delete() {
		boolean deleted = super.delete();
		if (deleted) { MessageKit.sendMessage(ACTION_DELETE, this); }
		return deleted;
	}

	@Override
	public boolean deleteById(Object idValue) {
		boolean deleted = super.deleteById(idValue);
		if (deleted) { MessageKit.sendMessage(ACTION_DELETE, this); }
		return deleted;
	}

	@Override
	public boolean update() {
		boolean update = super.update();
		if (update) { MessageKit.sendMessage(ACTION_UPDATE, this); }
		return update;
	}

	public void setFid(java.lang.String id) {
		set("fid", id);
	}

	public java.lang.String getFid() {
		Object id = get("fid");
		if (id == null)
			return null;
		return id.toString();
	}

	public java.lang.String getFtoken() {
		return get("ftoken");
	}
	public void setFtoken(java.lang.String ftoken) {
		set("ftoken", ftoken);
	}
	
	public java.lang.String getFurl() {
		return get("furl");
	}
	public void setFurl(java.lang.String furl) {
		set("furl", furl);
	}
	
	public java.lang.String getFctime() {
		return get("fctime");
	}
	public void setFctime(java.lang.String fctime) {
		set("fctime", fctime);
	}
	
	public java.lang.String getFendtime() {
		return get("fendtime");
	}
	public void setFendtime(java.lang.String fendtime) {
		set("fendtime", fendtime);
	}
	
	public java.lang.String getFtype() {
		return get("ftype");
	}
	public void setFtype(java.lang.String ftype) {
		set("ftype", ftype);
	}
	
	public java.lang.String getFdesc() {
		return get("fdesc");
	}
	public void setFdesc(java.lang.String fdesc) {
		set("fdesc", fdesc);
	}
	
	public java.lang.String getFremark() {
		return get("fremark");
	}
	public void setFremark(java.lang.String fremark) {
		set("fremark", fremark);
	}
	
	public java.lang.String getFstatus() {
		return get("fstatus");
	}
	public void setFstatus(java.lang.String fstatus) {
		set("fstatus", fstatus);
	}
	
}
